Skip to content

Search inside thread messages from the Cmd K palette - #445

Merged
abhishekgahlot2 merged 1 commit into
useagenthq:mainfrom
officialasishkumar:feature/search-thread-messages
Nov 13, 2026
Merged

abhishekgahlot2 merged 1 commit into
useagenthq:mainfrom
officialasishkumar:feature/search-thread-messages

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.

Fixes #91

⌘K only matched thread titles, so a thread you remembered by something the agent said could not be found. It now also searches what was said inside threads, lists the matches under the title matches with a snippet, and opens the thread at the turn that said it.

What changed

GET /api/runs/search (backend/src/runs/message-search.ts, route in read-routes.ts)

  • Searches the two texts a thread shows as messages: the prompts people typed (role: "user", runs.prompt) and the agent's replies (role: "agent", runs.summary).
  • Postgres full-text search on the simple configuration, so no language's stemming or stop words apply. Every query word has to be in the same message and matches from the start of a word: deplo stag finds "Deploy to staging", hook does not find "webhook".
  • The query goes through the same parser as the messages (to_tsvector('simple', q)), and each word is quoted as a prefix term ('word':*). Quotes, backslashes, &, |, ! and :* typed into the box are plain words, never tsquery syntax.
  • Before to_tsvector, an ILIKE check on each word (wildcards escaped) skips rows that cannot match. Every full-text match passes it, so it changes cost, not results. On 50,000 runs with long replies in one workspace: about 170 ms for a selective query, 350 ms for one matching every prompt, and 1.3 s for one matching every reply. Without the check every query took about 3.1 s.
  • Scope is the thread list's: the member's workspace, origin is null runs under an origin is null thread root (no automation or internal threads), and no gateway child sessions (they fold under their parent turn instead of showing as a message; same child-session: idempotency check repo.ts uses).
  • One match per thread, its newest matching message (a reply beats the prompt it answers), newest thread first. snippet is a ts_headline fragment around the match, in fragment mode so the words before the first match come along; thread_prompt is the root prompt the title comes from.
  • q is required and at most 200 characters (400). limit is 1 to 25, default 10.
  • Bounded: the query runs in a transaction with a 5 second statement_timeout, and a cut-off search answers 503 (read by SQLSTATE 57014 through sqlStateOf).

I did not add an index. A GIN index on runs would need either a blocking CREATE INDEX in a migration or the online-index path that src/db/online-indexes/ uses for canonical_events, and with the ILIKE check and the per-workspace idx_runs_org scan the timings above seemed fine for a first version. Happy to add one in a follow-up if you'd like.

The palette (frontend/components/shell/)

  • message-search.ts: the fetch through backendFetch, a decoder, and useMessageSearch. It asks after a 200 ms pause, only from 2 characters, and aborts the request a newer query replaces, so an older answer never shows over a newer query.
  • search-command.tsx renders a Messages group right under Threads: the snippet, in <thread title>, and You/Agent with the time. A thread already listed by title is not repeated for its first prompt.
  • While the answer is pending, a "Searching messages" row shows (Command.Loading) and the empty line stays hidden. A failed search says "Couldn't search messages. Change the search to try again." instead of reading as nothing found. The empty line now reads "No commands, threads or messages found".
  • The palette passes shouldFilter={false} to cmdk (new optional prop on CommandMenu.Dialog). Every list in it is already filtered by matchesEveryWord and ordered by rankThreads, and cmdk's scoring would hide message rows whose words are not in the row's value and reorder the rest. Empty groups are skipped explicitly, since cmdk no longer hides them.
  • CommandMenu.List gets min-w-0. Without it a long row (a snippet, or a long thread title) widened the list's grid column past the 600 px dialog and clipped every row's right-hand meta. I measured 833 px inside the 598 px dialog before, 598 px after.

Opening at the message (frontend/app/session/(thread)/[id]/page.tsx, components/chat/, components/session-ui/message-scroller-rail.tsx)

  • A match opens /session/:thread_id?message=:run_id. The page reads message from searchParams and passes it to SessionView, then on to Conversation as focusRunId.
  • Conversation jumps to that turn after its first follow-to-bottom, and stops following the bottom so streaming output does not scroll it away.
  • jumpToRunTurn (find the turn by data-run-id, then jumpToTurn) is now shared with the message rail.
  • holdRunTurn keeps the turn in place while the thread settles. In a long thread the turn window opens it as a sized placeholder, fetches it as it comes into view, and keeps another row still while heights change. I saw the turn drift by up to 2,357 px, or get swapped back to a placeholder, without this. Whenever any turn resizes it jumps back, until the reader scrolls, clicks or types anywhere on the page.
  • session-view.tsx is at its 990-line ratchet baseline, so the prop rides existing lines there.

Docs: the route and a paragraph on the Runs API page, the ?message= link on the Session view page, and the command palette card in Product experience.

Across a release: new route, new optional prop, and an optional query parameter. An old backend answers /api/runs/search through /:id with 404 run not found, so the new palette shows its failure line and title search still works.

Tests

backend/test/message-search.test.ts, through the real route and database:

  • a reply found by words in any order and as word prefixes, with the thread, run, role, root prompt, and a snippet that starts before the match. Words split across two messages, or matched mid-word, find nothing
  • one match per thread, the newest (a follow-up prompt over the root's reply; a reply over its own prompt)
  • 30 matching threads: newest first, default 10, limit=3, a limit over 25 held at 25, a non-number giving 10
  • another workspace's thread never returned, both ways
  • automation and internal-canary threads and a gateway child session left out
  • quotes, backslashes, (, &, |, !, :*, a path with _, and 100% read as plain words; punctuation alone finds nothing
  • a missing, blank or 201-character q answers 400

Frontend:

  • message-search.test.ts: the decoder, the request path and encoding, a 503 or an odd body thrown rather than read as no matches, the query rules, dropping a listed thread's title prompt, the href
  • message-search.interaction.test.tsx mounts the hook in happy-dom over a stubbed fetcher: one request after a burst of keystrokes, none under 2 characters, the in-flight request aborted and its late answer ignored, failed on a 503, idle again when cleared
  • message-scroller-rail.dom.test.ts: jumpToRunTurn on real nodes, and holdRunTurn with a fake ResizeObserver. It jumps back after the turn moves down or up, lets go on wheel, touch, pointer or key anywhere, and on cleanup

Checks with Bun 1.3.14, backend tests on pgvector/pgvector:0.8.6-pg16-bookworm:

  • bun run typecheck (root): passes
  • cd backend && bun run test: 3633 pass, 0 fail, then the Slack suite 119 pass, 0 fail
  • cd frontend && bun run test: 2001 pass, 0 fail
  • cd frontend && bun run lint: 248 warnings and 22 infos, the same as main
  • cd frontend && bun run build: passes
  • cd docs-site && bunx blume validate: no broken links
  • bun test scripts/agent-docs.test.ts: 5 pass

End to end

I ran a real backend on its own Postgres and a production build of the frontend (next start), signed up a member, and drove it with Playwright at 1440x900. The workspace had three threads: an 80-turn thread (long enough to load windowed) whose turn 5 reply mentions "the payment webhook", a short thread whose second reply mentions "our webhook endpoint", and a thread titled "Retry failed webhook deliveries".

  • ⌘K, typing webhook: Threads lists "Retry failed webhook deliveries". Messages lists "Stripe calls our webhook endpoint at /hooks/payments; failures land in the dead-letter queue", in Set up the staging deploy, Agent · 1h, and "The checkout test raced the payment webhook. I made it wait for the webhook before it asserts the order total", in Plan the checkout rewrite, Agent · 3d. The titled thread is not repeated under Messages. The footer reads 3 results, and every row's meta is visible.
  • Arrow down to the second message and Enter: the URL is /session/e2e-long-1?message=e2e-long-5. Turn 5 was an unloaded placeholder in that long thread. It was fetched as it came into view, and its top settled 8 px under the scroller's top (the rail's inset) with the reply visible. Same result on three runs.
  • Reloading the link directly lands the same way, for turn 5, for turn 60 (from the loaded tail), and for the root turn. Without ?message= the thread still opens at its newest turn.
  • dead-letter, a word said only inside a thread, shows just the Messages group, and Enter opens /session/e2e-short-1?message=e2e-short-2.
  • zzqx nothing shows "No commands, threads or messages found" once the search has answered.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Cmd K only matched thread titles, so a thread could be found only by its
first line. It now also finds the words said inside a thread and opens the
thread at the turn that said them.

GET /api/runs/search?q= (backend/src/runs/message-search.ts) searches the
two texts a thread shows as messages, the prompts people typed and the
agent's replies (runs.prompt and runs.summary), with Postgres full-text
search on the simple configuration:

- Every query word has to be in the same message, matched from the start
  of a word, so "deplo stag" finds "Deploy to staging". The query goes
  through the same parser as the messages and each word is quoted as a
  prefix term, so nothing typed is read as tsquery syntax.
- An ILIKE check on each word runs first. Every full-text match passes it,
  so only candidate rows pay for to_tsvector. On 50,000 runs with long
  replies in one workspace, a selective query took about 170 ms and one
  that matched every reply about 1.3 s; without the check every query
  took about 3.1 s.
- It reads only what the thread list shows: the member's workspace,
  user-created runs under a user-created root, and no gateway child
  sessions. It answers the newest matching message of each thread, newest
  thread first, with a ts_headline snippet around the match.
- The query runs under a 5 second statement_timeout and answers 503 when
  it is cut off. q is required and at most 200 characters; limit is 1 to 25.

The palette (frontend/components/shell/) asks after a 200 ms pause in
typing, aborts the request a newer query replaces, and lists the matches
in a Messages group under the title matches. A thread already listed by
title is not repeated for its first prompt. While the answer is pending
the empty line stays hidden, and a failed search says so instead of
reading as "nothing found". The palette now turns cmdk's own filtering
off, since every list in it is already filtered and ordered, and the list
gets min-w-0 so a long row no longer widens it past the dialog.

Picking a match opens /session/:thread?message=:run. The session page
passes the run id down and Conversation jumps to that turn, stops
following the bottom, and holds the turn in place while a long thread's
window fills in around it, until the reader scrolls, clicks or types. The
jump moved into jumpToRunTurn, which the message rail now shares.

Docs: the route on the Runs API page, the message link on the Session
view page, and the command palette card.
@abhishekgahlot2
abhishekgahlot2 merged commit 75d122f into useagenthq:main Nov 13, 2026
22 checks passed
@abhishekgahlot2

Copy link
Copy Markdown
Contributor

Merged, thanks @officialasishkumar. Finding a thread by something said inside it is a big step up for Cmd K, and the bound search term, workspace scoping and 5 s statement limit keep it safe. The GIN index you offered as a follow-up would be welcome.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search inside thread messages from ⌘K, not just titles

2 participants